﻿using Acme.ConcreteMixDesign.TopicInformations;
using Acme.ConcreteMixDesign.Type;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Acme.ConcreteMixDesign.Controllers
{
    [Route("api/app/TopicInformation")]
    public class InformationController : ConcreteMixDesignController, ITopicInformationService
    {
        private readonly ITopicInformationService _topicInformationService;

        public InformationController(ITopicInformationService topicInformationService)
        {
            _topicInformationService = topicInformationService;
        }
        [HttpGet]
        [Route("GetInfor")]
        public async Task<List<TopicInformationDto>> GetInfor()
        {
             return await _topicInformationService.GetInfor();
        }

        [HttpGet]
        [Route("GetInforMapByType")]
        public Task<List<TopicInformationDto>> GetInforMapByType(InformationType informationType)
        {
            return _topicInformationService.GetInforMapByType(informationType);
        }
        [HttpGet]
        [Route("GetMaterial")]

        public Task<FileDto> GetMaterialAsync(Guid Inforid)
        {
            return _topicInformationService.GetMaterialAsync(Inforid);
        }
        [HttpGet]
        [Route("MaterialDownload")]
        public async Task<IActionResult> MaterialDownloadAsync(Guid Inforid)
        {
            var Mater = await _topicInformationService.GetMaterialAsync(Inforid);
            if(Mater!=null)
            return File(Mater.FileStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", Mater.FileName);
            else
                return NotFound();
        }
        [HttpGet]
        [Route("SaveFlie")]
        public Task<TopicInformationDto> SaveFlie(IFormFile file, InformationType type)
        {
            return _topicInformationService.SaveFlie(file, type);
        }
    }
}
